* Code to reproduce “Online appendix D. Heckman selection model for the effect of local spending on OCV for 2010”, using the integrated “Dez_and_Death_integrated_dataset.dta” 
keep if year == 2010
tabulate Estado_ID, gen(Estado)

* variables related to security spending per capita and the local police pear capita are multiply imputed with 50 datased (M=50)	
mi set mlong
mi register imputed Sec_Spending_Cap_2010 Loc_Police_Per_Head
mi register regular CIDE_OC_deaths_Cap_Log Spending_Cap_Real Own_Revenue_Share gini poverty Share_Head_of_HH_Female Household_Size Population_Density  Population_15_29_Males  Males_Per_100_Females Indigenous_Pop_Share Population Munic_Size_Categ Laakso_Tag_Ind Dummy_Border_PCoast Estado1-Estado32
mi impute mvn Sec_Spending_Cap_2010 Loc_Police_Per_Head = CIDE_OC_deaths_Cap_Log Spending_Cap_Real Own_Revenue_Share gini poverty Share_Head_of_HH_Female Household_Size Population_Density  Population_15_29_Males  Males_Per_100_Females Indigenous_Pop_Share Population Munic_Size_Categ Laakso_Tag_Ind Dummy_Border_PCoast Estado1-Estado32, add(50) force
mi xeq 0 1 20 50: summarize Sec_Spending_Cap_2010 Loc_Police_Per_Head

* Computation of Heckman selection model (selection variables: Population and geographic location)
mi estimate, cmdok: heckman CIDE_OC_deaths_Cap_Log Spending_Cap_Real Own_Revenue_Share Sec_Spending_Cap_2010 Loc_Police_Per_Head gini poverty Share_Head_of_HH_Female Household_Size Population_Density  Population_15_29_Males  Males_Per_100_Females Indigenous_Pop_Share Munic_Size_Categ Laakso_Tag_Ind i.Estado_ID, select(Spending_Cap_Real Own_Revenue_Share Sec_Spending_Cap_2010 Loc_Police_Per_Head gini poverty Share_Head_of_HH_Female Household_Size Population_Density  Population_15_29_Males  Males_Per_100_Females Indigenous_Pop_Share Population Munic_Size_Categ Laakso_Tag_Ind Dummy_Border_PCoast i.Estado_ID) twostep

* Results and important additional parameters are stored in an excel file
putexcel set "resultsCS_2010_Heck.xlsx", sheet("OLS_2010_MI_OC_heck") modify
putexcel A100=("Number of obs")
putexcel B100=(e(N_mi))
putexcel A101=("Number of groups")
putexcel B101=(e(N_clust_mi))
putexcel A102=(" F-test")
putexcel B102=( e(F_mi))
putexcel A2= "effects_b"
putexcel A3= "variance_cov_matrix"
putexcel B2= matrix(e(b_mi))
putexcel B3= matrix(e(V_mi))
